package com.blacktech.dbu.meta.entity;

import com.blacktech.dbu.core.common.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 数据索引信息
 *
 * @author yanyunsong
 */
@Data
@Entity
@Table(name = "dbu_index")
@EqualsAndHashCode(callSuper = true)
public class DbuIndex extends BaseEntity {

    /**
     * 索引名称
     */
    @Column(name = "index_name")
    private String indexName;

    /**
     * 是否唯一索引
     */
    @Column(name = "unique_index")
    private Boolean uniqueIndex;

    /**
     * 索引涉及的字段列表
     */
    @ManyToMany
    @JoinTable(name = "dbu_index_column", joinColumns = @JoinColumn(name = "index_id"), inverseJoinColumns = @JoinColumn(name = "column_id"))
    @JsonIgnore
    private List<DbuColumn> columnList;

    /**
     * 关联的数据表
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "table_id")
    @JsonIgnore
    private DbuTable table;
}